#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case, non_upper_case_globals, unused_assignments, unused_mut)]
#![feature(extern_types)]
extern crate libc;
use primary::alloc_testing::*;
use primary::bloom_filter::*;
use primary::compare_pointer::*;
use primary::compare_string::*;
use primary::compare_int::*;
use primary::hash_pointer::*;
use primary::hash_string::*;
use primary::hash_int::*;
extern "C" {
    pub type _BloomFilter;
    fn __assert_fail(
        __assertion: *const libc::c_char,
        __file: *const libc::c_char,
        __line: libc::c_uint,
        __function: *const libc::c_char,
    ) -> !;
                                            }
#[no_mangle]
pub extern "C" fn test_bloom_filter_new_free() {
    let mut filter: *mut BloomFilter = std::ptr::null_mut();

    filter = bloom_filter_new(
        128,
        Some(string_hash),
        1,
    );
    assert!(!filter.is_null(), "filter != NULL");

    bloom_filter_free(filter);

    filter = bloom_filter_new(
        128,
        Some(string_hash),
        64,
    );
    assert!(!filter.is_null(), "filter != NULL");

    bloom_filter_free(filter);

    filter = bloom_filter_new(
        128,
        Some(string_hash),
        50000,
    );
    assert!(filter.is_null(), "filter == NULL");
}
#[no_mangle]
pub extern "C" fn test_bloom_filter_insert_query() {
    let mut filter: *mut BloomFilter = std::ptr::null_mut();

    filter = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );

    let filter_box = unsafe { Box::from_raw(filter) };

    assert_eq!(
        bloom_filter_query(
            filter,
            b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    assert_eq!(
        bloom_filter_query(
            filter,
            b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );

    bloom_filter_insert(
        filter,
        b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    bloom_filter_insert(
        filter,
        b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );

    assert_ne!(
        bloom_filter_query(
            filter,
            b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    assert_ne!(
        bloom_filter_query(
            filter,
            b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );

    filter = Box::into_raw(filter_box);
    bloom_filter_free(filter);
}
#[no_mangle]
pub extern "C" fn test_bloom_filter_read_load() {
    let mut filter1: *mut BloomFilter = std::ptr::null_mut();
    let mut filter2: *mut BloomFilter = std::ptr::null_mut();
    let mut state: [libc::c_uchar; 16] = [0; 16];

    filter1 = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );
    let filter1_box = unsafe { Box::from_raw(filter1) };
    bloom_filter_insert(
        filter1,
        b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    bloom_filter_insert(
        filter1,
        b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    bloom_filter_read(filter1, state.as_mut_ptr());
    filter1 = Box::into_raw(filter1_box);
    bloom_filter_free(filter1);

    filter2 = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );
    let filter2_box = unsafe { Box::from_raw(filter2) };
    bloom_filter_load(filter2, state.as_mut_ptr());
    filter2 = Box::into_raw(filter2_box);

    assert_ne!(
        bloom_filter_query(
            filter2,
            b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    assert_ne!(
        bloom_filter_query(
            filter2,
            b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    bloom_filter_free(filter2);
}
#[no_mangle]
pub extern "C" fn test_bloom_filter_intersection() {
    let mut filter1: *mut BloomFilter = std::ptr::null_mut();
    let mut filter2: *mut BloomFilter = std::ptr::null_mut();
    let mut result: *mut BloomFilter = std::ptr::null_mut();

    filter1 = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );
    let filter1_box = unsafe { Box::from_raw(filter1) };
    bloom_filter_insert(
        filter1,
        b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    bloom_filter_insert(
        filter1,
        b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    filter1 = Box::into_raw(filter1_box);

    filter2 = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );
    let filter2_box = unsafe { Box::from_raw(filter2) };
    bloom_filter_insert(
        filter2,
        b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    filter2 = Box::into_raw(filter2_box);

    assert_eq!(
        bloom_filter_query(
            filter2,
            b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );

    result = bloom_filter_intersection(filter1, filter2);
    let result_box = unsafe { Box::from_raw(result) };
    assert_ne!(
        bloom_filter_query(
            result,
            b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    assert_eq!(
        bloom_filter_query(
            result,
            b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    result = Box::into_raw(result_box);

    bloom_filter_free(result);
    bloom_filter_free(filter1);
    bloom_filter_free(filter2);
}
#[no_mangle]
pub extern "C" fn test_bloom_filter_union() {
    let mut filter1: *mut BloomFilter = std::ptr::null_mut();
    let mut filter2: *mut BloomFilter = std::ptr::null_mut();
    let mut result: *mut BloomFilter = std::ptr::null_mut();

    filter1 = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );
    bloom_filter_insert(
        filter1,
        b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    filter2 = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );
    bloom_filter_insert(
        filter2,
        b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
    );
    result = bloom_filter_union(filter1, filter2);

    assert_ne!(
        bloom_filter_query(
            result,
            b"test 1\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    assert_ne!(
        bloom_filter_query(
            result,
            b"test 2\0" as *const u8 as *const libc::c_char as BloomFilterValue,
        ),
        0
    );
    bloom_filter_free(result);
    bloom_filter_free(filter1);
    bloom_filter_free(filter2);
}
#[no_mangle]
pub extern "C" fn test_bloom_filter_mismatch() {
    let mut filter1: *mut BloomFilter = std::ptr::null_mut();
    let mut filter2: *mut BloomFilter = std::ptr::null_mut();

    filter1 = bloom_filter_new(
        128,
        Some(string_hash),
        4,
    );
    filter2 = bloom_filter_new(
        64,
        Some(string_hash),
        4,
    );

    let filter1_box = unsafe { Box::from_raw(filter1) };
    let filter2_box = unsafe { Box::from_raw(filter2) };

    assert!(bloom_filter_intersection(filter1, filter2).is_null());
    assert!(bloom_filter_union(filter1, filter2).is_null());

    filter2 = Box::into_raw(filter2_box);
    bloom_filter_free(filter2);

    filter2 = bloom_filter_new(
        128,
        Some(string_nocase_hash),
        4,
    );

    let filter2_box = unsafe { Box::from_raw(filter2) };

    assert!(bloom_filter_intersection(filter1, filter2).is_null());
    assert!(bloom_filter_union(filter1, filter2).is_null());

    filter2 = Box::into_raw(filter2_box);
    bloom_filter_free(filter2);

    filter2 = bloom_filter_new(
        128,
        Some(string_hash),
        32,
    );

    let filter2_box = unsafe { Box::from_raw(filter2) };

    assert!(bloom_filter_intersection(filter1, filter2).is_null());
    assert!(bloom_filter_union(filter1, filter2).is_null());

    filter2 = Box::into_raw(filter2_box);
    filter1 = Box::into_raw(filter1_box);
    bloom_filter_free(filter2);
    bloom_filter_free(filter1);
}
